Skip to content

Refactor date picker to be compatible with form#7627

Closed
sig5 wants to merge 56 commits into
Expensify:mainfrom
sig5:refactorDatePicker
Closed

Refactor date picker to be compatible with form#7627
sig5 wants to merge 56 commits into
Expensify:mainfrom
sig5:refactorDatePicker

Conversation

@sig5

@sig5 sig5 commented Feb 8, 2022

Copy link
Copy Markdown
Contributor

Details

  1. An optional isFormInput prop.
  2. If isFormInput is true, require a inputID prop. Use [getInputIDPropTypes] (https://github.com/Expensify/App/blob/1860b590114991d1819a5590608d26c32337de56/src/libs/FormUtils.js#L7)[] to enforce this propType rule.
  3. Add an optional shouldSaveDraft prop. Defaults to false.

Importing the baseTextInputPropTypes does the deal. I have added a propType for defaultValue to support both dates and strings as consistency in the value and defaultValue parameter is expected.

  1. Make the value prop optional.

The value prop is not a required prop.

5.In the input’s onBlur method, call props.onBlur().
6.In the input’s onChange method (or equivalent e.g. onTextChange, etc), call props.onChange().
7. Remove the hasError prop.

Done!

  1. Add an optional errorText prop. Defaults to an empty string.

Importing the baseTextInputPropTypes does the deal.

9.Update the error message to display if errorText is truth.
Error text is displayed only when non-empty!

  1. Update the inline error display style so it is left aligned with the label and input value.

Done! Strangely it hadn't been implemented for TextInput in the PR.

  1. Make sure that props.ref is attached to the appropriate DOM node. This could involve forwarding the ref to a child component. This is important so we can call ref.focus().

Done! Ref has been passed to TextInput elements because DatePicker doesn't natively support focus. These are handled via different methods. this.textInput.clear() and similar methods are accessible

  1. Add the input to the test Form stories and make sure that it works. You can check this by running npm run storybook and testing the component in the example form.

Done!

13 Remove any unused code.

Done!

There are a few more discretionary changes done. I will mention those in the comments.

Newly discovered Issues:
1.The datepicker doesn't get focussed on clicking in android/iOS.
2. The storybook sidebar UI styling is broken for mWeb.

Fixed Issues

$ #7536

Tests

  1. Run npm run storybook
  2. Play around with the Form stories and make sure that it works as intended. Specifically, note the following:
  • We can enter values into the inputs.
  • Clicking submit displays a loading indicator in the submit button and an alert with the correct input values.
  • Emptying the input value and blurring it shows an error.
  • Clicking the fix the errors link above the submit button focus on the first input with an error.
  • Entering a value in the input clears the error.
  • Verify that server errors are displayed correctly.
  • Any other fishy behavior.

Run the app and test that DatePicker still works fine.

  • Verify that no errors appear in the JS console

The errors observed were common to TextInput. Resolution of those should rectify the ones that appear here.

QA Steps

  • Verify that no errors appear in the JS console

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Kazam_screencast_00007.mp4

Mobile Web

WhatsApp.Video.2022-02-08.at.11.49.17.AM.mp4

Desktop

Kazam_screencast_00004.mp4

iOS

Kazam_screencast_00003.mp4

Android

Kazam_screencast_00002.mp4

Comment thread src/components/DatePicker/index.android.js Outdated
Comment thread src/components/DatePicker/index.js Outdated
@sig5 sig5 marked this pull request as ready for review February 8, 2022 06:33
@sig5 sig5 requested a review from a team as a code owner February 8, 2022 06:33
@MelvinBot MelvinBot removed the request for review from a team February 8, 2022 06:33
@rushatgabhane

rushatgabhane commented Feb 8, 2022

Copy link
Copy Markdown
Member

@sig5 videos for everything except mWeb aren't working, can you please reupload? I can only see a black screen.

Edit: this is happening only on mobile devices.

@rushatgabhane

Copy link
Copy Markdown
Member

The datepicker doesn't get focussed on clicking in android/iOS.

I believe this is the expected behaviour.

@sig5

sig5 commented Feb 8, 2022

Copy link
Copy Markdown
Contributor Author

Sorry for the misunderstanding, I meant that the textInput enclosed by datePicker should be focused on when we are selecting dates. See the PR Android video for context. The focus should be on DatePicker's textInput and the Keyboard should be hidden.

@luacmartins

Copy link
Copy Markdown
Contributor

@sig5 any updates?

@sig5

sig5 commented Mar 22, 2022

Copy link
Copy Markdown
Contributor Author

Hi @luacmartins, I was waiting for clarification on this thread : #7627 (comment) . We should be good to go once we reach a conclusion here :D

@luacmartins

luacmartins commented Mar 22, 2022

Copy link
Copy Markdown
Contributor

@sig5 Sorry I missed that! Replied to it just now. Thanks for the reminder!

@luacmartins

Copy link
Copy Markdown
Contributor

@sig5 I addressed the pending comments. Let me know if there's anything else that I missed. Thanks!

@sig5

sig5 commented Mar 28, 2022

Copy link
Copy Markdown
Contributor Author

Thank you for addressing the comments @luacmartins :D. I think the PR should be ready for review now.
cc: @rushatgabhane

@rushatgabhane rushatgabhane left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sig5 please merge main into your branch, and adress the requested changes.
Thanks!

Comment thread src/stories/Form.stories.js Outdated
Comment thread src/components/DatePicker/index.android.js Outdated
Comment thread src/components/DatePicker/index.android.js Outdated
Comment thread src/components/DatePicker/index.android.js Outdated
Comment thread src/components/DatePicker/index.android.js Outdated
Comment thread src/components/DatePicker/index.ios.js
Comment thread src/components/DatePicker/index.ios.js Outdated
@luacmartins

Copy link
Copy Markdown
Contributor

@sig5 when do you think you'll be able to address @rushatgabhane's comments?

@sig5

sig5 commented Apr 1, 2022

Copy link
Copy Markdown
Contributor Author

Hi @luacmartins, sorry I missed the notifications. I think I have addressed the comments mentioned by @rushatgabhane .

@luacmartins luacmartins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing @rushatgabhane's comments!

I'm not convinced that we need some of these additions, i.e. didComponentUpdate, value and selectedValue so I left a few more comments to try to understand this solution better.

Comment thread src/components/DatePicker/index.ios.js
Comment thread src/components/DatePicker/index.android.js
Comment thread src/components/DatePicker/index.android.js
Comment thread src/components/DatePicker/index.ios.js
Comment thread src/components/DatePicker/index.ios.js
Comment thread src/components/DatePicker/index.js

@luacmartins luacmartins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my concerns @sig5!

I left a comment about renaming onChange handler.

While testing DatePicker outside the form, I noticed a strange behavior where the date gets wiped when typing it a second time (see video below). We should make sure that we are not breaking any current usages of it.

date.mov

setDate(event, selectedDate) {
this.setState({isPickerVisible: false});
if (event.type === 'set') {
this.props.onChange(selectedDate);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we renamed onChange to onInputChange passed down by the form, so we should update it accordingly within DatePicker and in all usages of DatePicker

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing! I will update it.

@rushatgabhane

rushatgabhane commented Apr 7, 2022

Copy link
Copy Markdown
Member

@sig5 bump to address @ luacmartins' comments

@sig5

sig5 commented Apr 10, 2022

Copy link
Copy Markdown
Contributor Author

@luacmartins , I can't reproduce it.

@rushatgabhane

rushatgabhane commented Apr 11, 2022

Copy link
Copy Markdown
Member

@sig5 there is definitely something strange going on.

Are you sure you can't repro this? Please let me know the details if so. (platform, steps, screenshot?)

datepicker.mov

@sig5

sig5 commented Apr 14, 2022

Copy link
Copy Markdown
Contributor Author

@rushatgabhane could you please add the steps of reproduction?

@luacmartins

Copy link
Copy Markdown
Contributor

You can probably follow the videos, but something like:

  1. Enter a date in the date input.
  2. Try to edit the date
  3. When updating the date, parts of it get wiped and have a strange behavior.

@luacmartins

Copy link
Copy Markdown
Contributor

@sig5 any updates?

@luacmartins

Copy link
Copy Markdown
Contributor

Hey @sig5, are there any updates here?

@sig5

sig5 commented Apr 21, 2022

Copy link
Copy Markdown
Contributor Author

Hey folks, I have been encountering some health issues for a while due to which I am unable to allocateenough time for the issues, even after trying my best. The work in my PR's is approaching completion and interested individuals can fork my branch and continue working on it. Thanks.

@luacmartins

Copy link
Copy Markdown
Contributor

Thanks for the update @sig5 and I'm sorry to hear that. I'll pick up the issue to push this project forward. Thank you so much!

@luacmartins

Copy link
Copy Markdown
Contributor

Closing this PR in favor of #8770

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants